﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Net;
using System.Collections.Specialized;
using System.IO;
using System.Xml.Linq;
using System.Xml;


//$ANNOUNCEURL=http://tracker.chdbits.org/announce.php
//mktorrent -a $ANNOUNCE_URL -c $AUTHOR -l 20 -p -n $RELEASENAME $FILES

namespace CHDInfoGenerator
{
    class Program
    {
        static void Main(string[] args)
        {
            ReleaseEnvironment env;
            if (args.Length != 2)
            {
                Console.WriteLine("CHDInfoGenerator fileordirname catalog");
                return;
            }
            env = new ReleaseEnvironment(args[0], 8);
            env.Infos["RELEASECATALOG"] = args[1];
            env.Infos["SOURCETYPE"] = "HDTV MPEG-2 1080i";
            env.Infos["ALANGUAGE"] = "Mandarin";
            env.Infos["AUTHOR"] = "hothduser@CHDTV";
            env.Infos["LANGUAGE"] = "Chinese";
            env.Infos["DESCRIPTION"] = "DESCRIPTION";
            env.Infos["POSTER"] = "[img]POSTER[/img]";
            env.Infos["CASTIMG"] = "[img]CASTIMG[/img]";
            File.WriteAllText(env.Infos["RELEASENAME"] + ".nfo", env.Parse(System.Text.ASCIIEncoding.ASCII.GetString(File.ReadAllBytes("template.nfo"))));
            File.WriteAllText(env.Infos["RELEASENAME"] + ".desc", env.Parse(System.Text.ASCIIEncoding.ASCII.GetString(File.ReadAllBytes("template.desc"))));
            env.exeAndGetOutput("mktorrent", "-a http://tracker.chdbits.org/announce.php -c \"" + env.Infos["AUTHOR"] + "\" -l 21 -p -n \"" + env.Infos["RELEASEFILES"] + "\" -o \"" + env.Infos["RELEASENAME"] + ".torrent\" \"" + env.Infos["FILES"] + "\"");
        }
    }
}
